const App = getApp();
Page({

  data: {
    // 页面元素
    pic: '../../images/指向-bottom.png',
    topData: {},
    status: true,
    status1: true,
    scrollLeft: '',
    currentIndex: 0,
    pageNo: 1,
    list: [],
    action: '',
    tabs: [
      { key: 'today_clue', title: '当日线索' },
      { key: 'time_out', title: '即将超时' },
      { key: 'inspect', title: '预约带看' }
    ]
  },
 
  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function () {
    // this.selectComponent('#list-com').getCustomersList(value)
    let { tabs, currentIndex } = this.data
    this.getHomeTopData()
    this.selectComponent('#list-com').getCustomersList(tabs[currentIndex].key)
    let token = wx.getStorageSync('token')
    let role_id = wx.getStorageSync('role_id')
    if (token == null || token == undefined || token == '') {
      wx.redirectTo({
        url: '../login/login',
      })
    }
  },
  onLoad: function (options) {
  },
  /**
   * tab切换
   */
  handleTab(e) {
    let { index, value } = e.currentTarget.dataset
    const child = this.selectComponent('#list-com')
    child.setData({
      deviceList: [],
      deviceIndex: 1
    })
    this.setData({
      currentIndex: index,
      action: value
    })
    this.selectComponent('#list-com').getCustomersList(value)
  },
  handleChange() {
    this.setData({
      status: !this.data.status
    })
    console.log(this.data.status, this.data.pic)
  },

  filterList(arr) {
    for (let index = 0; index < arr.length; index++) {
      arr[index].pic = ''
      switch (arr[index].level) {
        case 'A':
          arr[index].pic = '../../images/A.png'
          break;
        case 'B':
          arr[index].pic = '../../images/B.png'
          break;
        case 'C':
          arr[index].pic = '../../images/C.png'
          break;
        case 'D':
          arr[index].pic = '../../images/D.png'
          break;
        case 'T':
          arr[index].pic = '../../images/T.png'
          break;
        default:
          break;
      }
    }
  },
  getHomeTopData() {
    let _this = this
    App._post_form('home/getHomeTopData', {

    }, function (result) {
      console.log(result);
      _this.setData({
        topData: result.data
      })
    })
  },
  
  onReachBottom: function () {
    // 页面触底时执行
    this.selectComponent('#list-com').reachBottom(this.data.action, this.data.pageNo)
  },
  /**
   * 下拉刷新
   */
  onPullDownRefresh: function () {
    // 获取首页数据
    this.onShow()
  },
});